package dk.fuddi.conversion;

import dk.fuddi.commons.Hex;
import dk.fuddi.exception.EnDecodeException;

/**
 * User: jen
 * Date: May 27, 2008
 * Time: 1:56:18 PM
 */
public class HexUtils implements DeEncodeInterface {

	private String name = "Hex";

	public String encode(String data) {
		System.out.println("HexUtils.encode");
		return String.valueOf(Hex.encodeHex(data.getBytes()));
	}

	public String decode(String data) throws EnDecodeException {
		System.out.println("HexUtils.decode");
		try {
			return new String(Hex.decodeHex(data.toCharArray()));
		} catch (Exception e) {
			e.printStackTrace();
			System.err.println("Could not decode hex data [" + data + "] " + e.getMessage());
			throw new EnDecodeException(e.getMessage());
		}
	}

	public String toString() {
		return name;
	}
}
